//Create results using caloric potential as measure of wealth

version 15.1

clear
/*If you need the estout package run 
ssc install estout, replace*/
use "worms_replication.dta"
set more off

***generate time counter***
gen time = year - 324

***set caloric potential as measure of wealth and generate interactions***
gen wealth =  calories
gen ConcWealth = Concordats*wealth
gen time_wealth = time*wealth

label var wealth "Wealth"
label var ConcWealth "Concordats * Wealth"
label var time_wealth "Time Trend * Wealth"
	
*Create half century counters*
gen half_century = 50*floor(year/50)
label var half_century "Half Century"
quietly forval i = 3/18{
	gen HC`i'0 = 0
	gen HC`i'5 = 0
	replace HC`i'0 = 1 if year >= `i'*100 -50 & year <`i'*100
	replace HC`i'5 = 1 if year >= `i'*100 & year <`i'*100 + 50
	}

*Create kingdom and grid cell by half-century dummies
gen kingdom_hc =  half_century + .0001* kingdom_id 
gen grid400_hc = half_century + .001*grid_group_400

	
/* Collapse data to diocese-bishop observations */
sort diocese year
drop if byearin != year 



*MAIN REGRESSION: Table 1 Row 2 is the coefficient on ConcWealth in each of these regressions in order***
reghdfe  religious_bishop ConcWealth Concordats crusade1 crusade2 crusade3 crusade4,  a(iddiocese half_century) vce(cluster iddiocese)
reghdfe  religious_bishop ConcWealth Concordats      crusade1 crusade2 crusade3 crusade4,  a(iddiocese  half_century monarch_id) vce(cluster iddiocese)
reghdfe  religious_bishop ConcWealth Concordats crusade1 crusade2 crusade3 crusade4,  a(iddiocese kingdom_hc ) vce(cluster iddiocese)
reghdfe  religious_bishop ConcWealth Concordats      crusade1 crusade2 crusade3 crusade4,  a(iddiocese grid400_hc ) vce(cluster iddiocese)
reghdfe  religious_bishop ConcWealth Concordats crusade1 crusade2 crusade3 crusade4 time_wealth,  a(iddiocese half_century) vce(cluster iddiocese)

***Table C.2 Row 2: Same as MAIN REGRESSION, but with a balanced panel of dioceses***
reghdfe  religious_bishop ConcWealth Concordats crusade1 crusade2 crusade3 crusade4 if minyear <= 800 & maxyear >= 1309,  a(iddiocese half_century) vce(cluster iddiocese)
reghdfe  religious_bishop ConcWealth Concordats      crusade1 crusade2 crusade3 crusade4 if minyear <= 800 & maxyear >= 1309,  a(iddiocese  half_century monarch_id) vce(cluster iddiocese)
reghdfe  religious_bishop ConcWealth Concordats crusade1 crusade2 crusade3 crusade4 if minyear <= 800 & maxyear >= 1309,  a(iddiocese kingdom_hc ) vce(cluster iddiocese)
reghdfe  religious_bishop ConcWealth Concordats      crusade1 crusade2 crusade3 crusade4 if minyear <= 800 & maxyear >= 1309,  a(iddiocese grid400_hc ) vce(cluster iddiocese)
reghdfe  religious_bishop ConcWealth Concordats  crusade1 crusade2 crusade3 crusade4 time_wealth if minyear <= 800 & maxyear >= 1309,  a(iddiocese half_century) vce(cluster iddiocese)


***Table C.3 Row 2: Same as MAIN REGRESSION, but clustering standard errors by kingdon-half-century

reghdfe  religious_bishop ConcWealth Concordats crusade1 crusade2 crusade3 crusade4,  a(iddiocese half_century) vce(cluster kingdom_hc)
reghdfe  religious_bishop ConcWealth Concordats      crusade1 crusade2 crusade3 crusade4,  a(iddiocese  half_century monarch_id) vce(cluster iddiocese)
reghdfe  religious_bishop ConcWealth Concordats crusade1 crusade2 crusade3 crusade4,  a(iddiocese kingdom_hc ) vce(cluster kingdom_hc)
reghdfe  religious_bishop ConcWealth Concordats      crusade1 crusade2 crusade3 crusade4,  a(iddiocese grid400_hc ) vce(cluster kingdom_hc)
reghdfe  religious_bishop ConcWealth Concordats crusade1 crusade2 crusade3 crusade4 time_wealth,  a(iddiocese half_century) vce(cluster kingdom_hc)
